package messaging.jmx;

import java.util.ArrayList;
import java.util.List;

import javax.management.MBeanException;
import javax.management.ObjectName;
import javax.naming.InitialContext;

import messaging.JMSMessagingConstants;

import org.jboss.jmx.adaptor.rmi.RMIAdaptor;

public class QueueDestroyer implements JMSMessagingConstants {

	/**
	 * @param args
	 * @throws Exception 
	 */
	public static void main(String[] args) throws Exception {
		System.out.println("Destroying Queues!");
		InitialContext ic = new InitialContext();
		RMIAdaptor server = (RMIAdaptor) ic.lookup("jmx/rmi/RMIAdaptor");
		List<String> queueJndiNames = new ArrayList<String>();
		queueJndiNames.add(SPEC_OUTPUT_ARCH_INPUT);
		queueJndiNames.add(ARCH_OUTPUT_IMPL_INPUT);
		queueJndiNames.add(ARCH_OUTPUT_UI_INPUT);
		queueJndiNames.add(IMPL_OUTPUT_INTEGRATION_INPUT);
		queueJndiNames.add(UI_OUTPUT_INTEGRATION_INPUT);
		queueJndiNames.add(INTEGRATION_OUTPUT_TEST_INPUT);
		queueJndiNames.add(TEST_OUTPUT_REPAIR_INPUT);
		queueJndiNames.add(RELEASE_INPUT);
		String[] signature = {"java.lang.String"};
		ObjectName name = new ObjectName("jboss.mq:service=DestinationManager");
		for (String jndiName : queueJndiNames) {
			try {
				server.invoke(name, "destroyQueue", new Object[]{jndiName}, signature);
				System.out.println("Queue destroyed: " + jndiName);
			} catch (MBeanException e) {
				System.err.println("Queue not exists: " + jndiName);
			}
		}
		System.out.println("Queue destruction finished!");
	}

}
